
#ifndef COLORREPLACER_H
#define COLORREPLACER_H

#include <BMap>
#include <BColor>
#include <BImage>
#include <BPointArray>

#include "ImageLayer.h"
#include "Operation.h"

class ColorReplacer : public Operation
{
public:
	ColorReplacer();
	~ColorReplacer();

	void setMatchColor(BColor color);
	void setMatchTolerance(int tolerance);
	void setTargetColor(BColor color);
	void setOnlyConstituency(bool constituency);

	void showMatchedGraph();
	void hideMatchedGraph();

	void replace();

protected:
	virtual void attached(BWidget* widget);
	virtual void detached(BWidget* widget);

	virtual void paint(BPainter& painter);

	virtual void freshEvent(const BEvent& event);

	virtual bool focusEvent(const BEvent& event);
	virtual bool keyDownEvent(const BKeyEvent& keyEvent);
	virtual bool keyUpEvent(const BKeyEvent& keyEvent);

	virtual bool mouseEnterEvent(const BMouseEvent& mouseEvent);
	virtual bool mouseLeaveEvent(const BMouseEvent& mouseEvent);
	virtual bool mousePressEvent(const BMouseEvent& mouseEvent);
	virtual bool mouseReleaseEvent(const BMouseEvent& mouseEvent);
	virtual bool mouseMoveEvent(const BMouseEvent& mouseEvent);

private:
	BColor			_matchColor;
	int				_matchTolerance;
	BColor			_targetColor;
	bool			_onlyConstituency;
	bool			_dirtyPoints;
	BMap<ImageLayer*, BPointArray>	_layerPointsMap;
};

#endif
